<template>
	<!-- 实名认证1 -->
	<view :class="model+'-wrap'">
		<view :class="'p-sticky-'+model+' '+(model=='light'?'p-stickyLight':'')">
			<view class="status_bar">
		
			</view>
			<view class="nav_bar flex align-center justify-between">
				<view @click="$tool.goBack()" class="f0 p-3">
					<image class="fanhui_icon" :src="'/static/images/fanhui_'+model+'.png'" mode=""></image>
				</view>
				<view class="A-Medium" :class="'navTitle_'+model">
					{{i18n.t005}}
				</view>
				<view class="f0 p-3 opacity0">
					<image class="fanhui_icon" :src="'/static/images/fanhui_'+model+'.png'" mode=""></image>
				</view>
			</view>
		</view>
		<view class="pt-3">
			
		</view>
		<view class="formWrap px-5 A-Regular">
			<view class="formTitle">
				{{i18n.t006}}
			</view>
			<view class="inputWrap px-3 flex align-center" :class="model=='light'?'inputWrapLight':''">
				<input disabled type="text" v-model="coinType"
					class="flex-1 inputText A-Medium" :class="model=='light'?'inputTextLight':''"
					:placeholder-class="'placeholderClass A-Medium',model=='light'?'placeholderClassLight':''">
			</view>
			<view class="formTitle">
				{{i18n.t007}}
			</view>
			<view @click="openPopup" style="margin-bottom: 0;" class="inputWrap px-3 flex align-center" :class="model=='light'?'inputWrapLight':''">
				<input type="text" v-model="coinNetwork" disabled 
					class="flex-1 inputText A-Medium" :class="model=='light'?'inputTextLight':''"
					:placeholder-class="'placeholderClass A-Medium',model=='light'?'placeholderClassLight':''">
				<!-- <view class="f0">
					<image style="width: 18rpx;height: 12rpx;" :src="'/static/images/downArrow_'+model+'.png'" mode="">
					</image>
				</view> -->
			</view>
			<view class="codeDesc mt-1 A-Medium mb-3">
				{{i18n.t008}}
			</view>
			<view class="formTitle">
				{{i18n.t009}}
			</view>
			<view class="inputWrap px-3 flex align-center" :class="model=='light'?'inputWrapLight':''">
				<input v-model="withdrawAddress" type="text" :placeholder="i18n2.st029"
					class="flex-1 inputText A-Medium" :class="model=='light'?'inputTextLight':''"
					:placeholder-class="'placeholderClass A-Medium',model=='light'?'placeholderClassLight':''">
			</view>
			<view class="formTitle">
				{{i18n.t010}}
			</view>
			<view class="inputWrap px-3 flex align-center" :class="model=='light'?'inputWrapLight':''">
				<input v-model="addressName" type="text" :placeholder="i18n2.st030"
					class="flex-1 inputText A-Medium" :class="model=='light'?'inputTextLight':''"
					:placeholder-class="'placeholderClass A-Medium',model=='light'?'placeholderClassLight':''">
			</view>
		</view>
		<!-- 下一步 -->
		<view @click="submit" class="btn mx-auto A-Medium mt-6 clickCss">
			{{i18n.t011}}
		</view>
	</view>
</template>

<script>
	import {
		withdrawAddressAdd,
		withdrawAddressQueryById,
		withdrawAddressEdit
	} from '@/core/api/index.js';
	export default {
		data(){
			return {
				id:0,
				coinType:'',
				coinNetwork:'',
				addressName:'',
				withdrawAddress:'',
				isSubmit:false,
			}
		},
		onReady() {
			this.$tool.setStatusBarStyle(this.model);
		},
		onShow() {
			this.$tool.setStatusBarStyle(this.model);
			const pages = getCurrentPages();
			const page = pages[pages.length - 1];
			const currentWebview = page.$getAppWebview();
			if(this.model == "dark"){
				currentWebview.setStyle({
					background: "#0E0F11"
				});
			}else{
				currentWebview.setStyle({
					background: "#ffffff"
				});
			}
		},
		computed: {
			i18n() {
				return this.$t('txAddress');
			},
			i18n2() {
				return this.$t('showToast');
			},
			model() {
				return this.$store.state.config.model;
			}
		},
		onLoad(options) {
			if(options.id){
				this.id = options.id;
				withdrawAddressQueryById({
					id:this.id
				}).then(res=>{
					let obj = res.result;
					this.withdrawAddress = obj.withdrawAddress;
					this.addressName = obj.addressName;
				})
			}
			this.coinType = uni.getStorageSync('txType');
			this.coinNetwork = uni.getStorageSync('coinNetwork');
		},
		methods:{
			submit(){
				if(this.withdrawAddress==='') return this.$tool.showToast(this.i18n2.st029);
				if(this.addressName==='') return this.$tool.showToast(this.i18n2.st031);
				let data = {
					addressName:this.addressName,
					coinNetwork:this.coinNetwork,
					coinType:this.coinType,
					mobileUserId:uni.getStorageSync('mobileUserId'),
					withdrawAddress:this.withdrawAddress
				}
				if(this.isSubmit){
					return;
				}else{
					this.isSubmit = true;
				}
				if(this.id===0){
					withdrawAddressAdd(data).then(res=>{
						uni.hideLoading();
						this.$tool.showToast(this.i18n2.st032);
						setTimeout(res=>{
							this.$tool.goBack();
						},800)
					}).catch(err=>{
						this.isSubmit = false;
						uni.hideLoading();
					})
				}else{
					data.id = this.id;
					withdrawAddressEdit(data).then(res=>{
						uni.hideLoading();
						this.$tool.showToast(this.i18n2.st032);
						setTimeout(res=>{
							this.$tool.goBack();
						},800)
					}).catch(err=>{
						this.isSubmit = false;
						uni.hideLoading();
					})
				}
			},
			openPopup(){
				
			}
		}
	}
</script>

<style scoped lang="scss">
	.codeDesc {
		font-size: 24rpx;
		color: #7F838D;
	}
	// 弹窗---开始
	.popupWrap {
		background: #0E0F11;
		font-size: 32rpx;
		color: #F7F7F7;
		.titleWrap {
			margin-bottom: 6rpx;
			image {
				width: 36rpx;
				height: 36rpx;
			}
		}
		.list {
			text-align: center;
			border-bottom: 2rpx solid #1F2128;
		}
		.listLight {
			border-bottom: 2rpx solid #F4F4F4;
		}
	}
	.popupWrapLight {
		background: #ffffff;
		color: #0E0F11;
	}
	// 弹窗---结束
	.p-stickyLight {
		background: #fff;
	}
	.formWrap {
		.formTitle {
			font-size: 28rpx;
			color: #7F838D;
			margin-bottom: 22rpx;
		}
	
		.inputWrap {
			width: 650rpx;
			height: 88rpx;
			background: #16181C;
			border-radius: 12rpx 12rpx 12rpx 12rpx;
			margin-bottom: 35rpx;
			
			.inputText {
				font-size: 28rpx;
				color: #F7F7F7;
				// text-align: right;
			}
			
			.inputTextLight {
				color: #0E0F11;
			}
			
			.placeholderClass {
				font-size: 28rpx;
				color: #7F838D;
			}
	
			.placeholderClassLight {
				color: #B5B7BF;
			}
	
			.img2 {
				width: 44rpx;
				height: 44rpx;
			}
		}
	
		.inputWrapLight {
			background: #FFFFFF;
		}
	}
	.codeDesc {
		font-size: 24rpx;
		color: #7F838D;
		.xing {
			color: #5951BA;
		}
	}
	.btn {
		width: 650rpx;
		height: 80rpx;
		background: #5951BA;
		border-radius: 74rpx;
		text-align: center;
		line-height: 80rpx;
		font-size: 28rpx;
		color: #F7F7F7;
	}
</style>